package com.guigu.utils.test;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;

import org.junit.Test;

import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.guigu.utils.bean.ExcelReaderFactory;

public class ExcelReadRow {

	public static void main(String[] args) {
		try {
			read();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	public static void read() throws Exception {
		String inputPath = "D:\\tmp\\excel\\withHead.xlsx";

		try (InputStream in = new FileInputStream(inputPath);) {
			AnalysisEventListener<List<String>> listener = new AnalysisEventListener<List<String>>() {

				@Override
				public void invoke(List<String> object, AnalysisContext context) {
					System.err.println("Row:" + context.getCurrentRowNum() + " Data:" + object);
				}

				@Override
				public void doAfterAllAnalysed(AnalysisContext context) {
					System.err.println("doAfterAllAnalysed...");
				}
			};
			ExcelReader excelReader = ExcelReaderFactory.getExcelReader(in, null, listener);
			excelReader.read();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
